package org.hive.vmware.server;

import java.util.List;

import org.hive.vmware.client.model.HostTreeFolder;
import org.hive.vmware.client.model.VmGroupVO;
import org.hive.vmware.client.model.VmVO;

public class DummyData {

	HostTreeFolder[] createDummyHosts(String serverCenterId, GwtVmwareServiceImpl gwtVmwareServiceImpl) {
		HostTreeFolder[] folders = new HostTreeFolder[4];
		List<VmGroupVO> vmGroups = gwtVmwareServiceImpl.loadVmGroups();
		for (int i = 0; i < folders.length; i++) {
			folders[i] = new HostTreeFolder("pod" + i, createDummyVms(vmGroups, serverCenterId, "pod" + i));
		}
		return folders;
	}

	private VmVO[] createDummyVms(List<VmGroupVO> vmGroups, String serverCenter, String hostName) {
		VmVO[] vms = new VmVO[4];
		for (int i = 0; i < vms.length; i++) {
			VmVO vm = new VmVO();
			vm.setName("vm" + i);
			vm.setHost(hostName);
			vm.setCenterServer(serverCenter);
			vm.setDescription(vm.getName() + "/" + hostName);
			vm.setVmGroupVO(findGroup(vmGroups, vm));
			vms[i] = vm;
		}
		return vms;
	}
	
	VmGroupVO findGroup(List<VmGroupVO> vmGroups, VmVO vm) {
		VmGroupVO result = null;
		for (VmGroupVO vmGroupVO : vmGroups) {
			List<VmVO> vms = vmGroupVO.getVms();
			for (VmVO vmVO : vms) {
				if (vmVO.getName().equals(vm.getName()) 
						&& vmVO.getHost().equals(vm.getHost())) {
					System.out.println("found!");
					return vmGroupVO;
				}
			}
		}
		return result;
	}
}
